import request from '@/utils/request'

const baseURL = '/enterpriseQuarterlyReport'

/**
 * 保存或更新公司指标明细表
 * (ID,指标名称,计量单位,本期值,上年值,同比变化率,产值及能源消费变化情况说明,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *   year: string;
 *   quarter: string;
 *   list: {
 *      id?: string;
 *      indicatorName?: string;
 *      unitOfMeasurement?: string;
 *      currentValue?: string;
 *      previousYearValue?: string;
 *      yearOnYearChangeRate?: string;
 *      remark?: string;
 *      year?: string;
 *      quarter?: string;
 *      state?: string;
 *      illustrate?: string;
 *   }[]
 * }}
 * @returns {Promise<ResponseData<any>>}
 */
export function saveOrUpdateCompanyIndicatorDetails (data) {
  return request({
    url: `${baseURL}/saveOrUpdateCompanyIndicatorDetails`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新公司产品信息
 * (ID,主要产品名称,数量,计量单位,数量1,计量单位1,数值,计量单位2,备注,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *      id?: string;
 *      productName?: string;
 *      quantity?: string;
 *      unitOfMeasurement?: string;
 *      quantityOne?: string;
 *      unitOfMeasurementOne?: string;
 *      numericalValue?: string;
 *      unitOfMeasurementTwo?: string;
 *      remark?: string;
 *      year?: string;
 *      quarter?: string;
 *      state?: string;
 *      illustrate?: string;
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateCompanyProduct (data) {
  return request({
    url: `${baseURL}/saveOrUpdateCompanyProduct`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新能源消费结构信息
 * (ID,能源名称,计量单位,代码,期初库存量,实物量,金额,合计,工业生产消费,用于原材料,非工业生产消费,合计中:运输工具消费,期末库存量,采用折标系数,参考折标系数,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *      id?: string;
 *      energyName?: string;
 *      unitOfMeasurement?: string;
 *      code?: string;
 *      beginningInventory?: string;
 *      physicalQuantity?: string;
 *      amount?: string;
 *      total?: string;
 *      industrialProduction?: string;
 *      forRawMaterials?: string;
 *      nonIndustrialProduction?: string;
 *      transportationConsumption?: string;
 *      endingInventory?: string;
 *      useScalingFactor?: string;
 *      referenceDiscountFactor?: string;
 *      year?: string;
 *      quarter?: string;
 *      state?: string;
 *      illustrate?: string;
 *    }[]
 * }}
 * @returns {Promise<any>}
 */
export function saveOrUpdateEnergyConsumptionStructure (data) {
  return request({
    url: `${baseURL}/saveOrUpdateEnergyConsumptionStructure`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新能源消费结构附表
 * (ID,能源名称,计量单位,代码,工业生产消费量,加工转换投入合计,火力发电,供热,原煤入洗,炼焦,炼油,制气,天然气液化,加工煤制品,能源加工转换产出,能源加工转换产出折标量,回收利用,采用折标系数,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *      id?: string,
 *      energyName?: string,
 *      unitOfMeasurement?: string,
 *      code?: string,
 *      industrialProduction?: string,
 *      machiningConversion?: string,
 *      thermalPowerGeneration?: string,
 *      heating?: string,
 *      rawCoalIsWashed?: string,
 *      coking?: string,
 *      refining?: string,
 *      gasProduction?: string,
 *      naturalGasLiquefaction?: string,
 *      processedCoalProducts?: string,
 *  conversionOutput?: string,
 *  conversionOutputDiscount?: string,
 *  recycleAndReuse?: string,
 *  useScalingFactor?: string,
 *  referenceDiscountFactor?: string,
 *  year?: string,
 *  quarter?: string,
 *  state?: string,
 *  illustrate?: string
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateEnergyConsumptionStructureSchedule (data) {
  return request({
    url: `${baseURL}/saveOrUpdateEnergyConsumptionStructureSchedule`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新主要耗能设备状况信息
 * (ID,序号,设备类型,设备名称,型号,功率/容量,主要技术参数,负载率,运行时间,设备大修,故障,是否属于淘汰设备,计划更新时间,项目,指标,备注,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 * id?: string,
 *  serialNumber?: string,
 *  equipmentType?: string,
 *  equipmentName?: string,
 *  model?: string,
 *  powerCapacity?: string,
 *  mainTechnicalParameters?: string,
 *  loadRate?: string,
 *  operationHours?: string,
 *  equipmentOverhaul?: string,
 *  fault?: string,
 *  retireEquipment?: string,
 *  scheduledUpdateTime?: string,
 *  project?: string,
 *  index?: string,
 *  remark?: string,
 *  year?: string,
 *  quarter?: string,
 *  state?: string,
 *  illustrate?: string
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateEquipmentStatus (data) {
  return request({
    url: `${baseURL}/saveOrUpdateEquipmentStatus`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新进度节能目标完成情况
 * (ID,项目名称,计量单位,第一年,第一年备注,第二年,第二年备注,第三年,第三年备注,第四年,第四年备注,第五年,第五年备注,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *       id?: string,
 *  projectName?: string,
 *  unitOfMeasurement?: string,
 *  oneYear?: string,
 *  oneRemark?: string,
 *  twoYear?: string,
 *  twoRemark?: string,
 *  threeYear?: string,
 *  threeRemark?: string,
 *  fourYear?: string,
 *  fourRemark?: string,
 *  fiveYear?: string,
 *  fiveRemark?: string,
 *  year?: string,
 *  quarter?: string,
 *  state?: string,
 *  illustrate?: string
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateGoalCompletionStatus (data) {
  return request({
    url: `${baseURL}/saveOrUpdateGoalCompletionStatus`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新单位产品综合能耗信息
 * (ID,指标名称,指标单位,子项单位,母项单位,单位换算系数,代码,指标值,子项值,母项值,国家(地区)限额,影响指标变化因素的说明,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *       id?: string,
 *  name?: string,
 *  unit?: string,
 *  subunit?: string,
 *  parentUnit?: string,
 *  unitConversionFactor?: string,
 *  code?: string,
 *  indexValue?: string,
 *  childValue?: string,
 *  parentValue?: string,
 *  areaQuota?: string,
 *  remark?: string,
 *  year?: string,
 *  quarter?: string,
 *  state?: string,
 *  illustrate?: string
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateProductEnergyConsumption (data) {
  return request({
    url: `${baseURL}/saveOrUpdateProductEnergyConsumption`,
    method: 'post',
    data,
  })
}

/**
 * 保存或更新节能改造项目信息
 * (ID,项目名称,投资金额,节能效果,是否合同能源管理模式,项目进度,审批部门,主要改造内容,年度,季度,状态,驳回说明)
 * @param data{{
 *   tenantId?: string;
 *    year: string;
 *    quarter: string;
 *    list: {
 *       id?: string,
 *  projectName?: string,
 *  investmentAmount?: string,
 *  energySavingProject?: string,
 *  contractEnergyManagement?: string,
 *  projectProgress?: string,
 *  approvalDepartment?: string,
 *  mainTransformationContent?: string,
 *  year?: string,
 *  quarter?: string,
 *  state?: string,
 *  illustrate?: string
 *    }[]
 * }}
 * @returns {*}
 */
export function saveOrUpdateReconstructionProject (data) {
  return request({
    url: `${baseURL}/saveOrUpdateReconstructionProject`,
    method: 'post',
    data,
  })
}

/**
 * 查询当前企业各季度上报状态
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadReportingSituation (params = {}) {
  return request({
    url: `${baseURL}/loadReportingSituation`,
    params,
  })
}

/**
 * 查询当前政府下企业各季度上报状态
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadReportingSituationList (params = {}) {
  return request({
    url: `${baseURL}/loadReportingSituationList`,
    params,
  })
}

/**
 * 查看某个企业的公司指标明细信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadCompanyIndicatorDetails (params = {}) {
  return request({
    url: `${baseURL}/loadCompanyIndicatorDetails`,
    params,
  })
}

/**
 * 查看某个企业的公司产品信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadCompanyProduct (params = {}) {
  return request({
    url: `${baseURL}/loadCompanyProduct`,
    params,
  })
}

/**
 * 查看某个企业的能源消费结构信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadEnergyConsumptionStructure (params = {}) {
  return request({
    url: `${baseURL}/loadEnergyConsumptionStructure`,
    params,
  })
}

/**
 * 查看某个企业的能源消费结构附表
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadEnergyConsumptionStructureSchedule (params = {}) {
  return request({
    url: `${baseURL}/loadEnergyConsumptionStructureSchedule`,
    params,
  })
}

/**
 * 查看某个企业的主要耗能设备状况信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadEquipmentStatus (params = {}) {
  return request({
    url: `${baseURL}/loadEquipmentStatus`,
    params,
  })
}

/**
 * 查看某个企业的进度节能目标完成情况
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadGoalCompletionStatus (params = {}) {
  return request({
    url: `${baseURL}/loadGoalCompletionStatus`,
    params,
  })
}

/**
 * 查看某个企业的单位产品综合能耗信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadProductEnergyConsumption (params = {}) {
  return request({
    url: `${baseURL}/loadProductEnergyConsumption`,
    params,
  })
}

/**
 * 查看某个企业的节能改造项目信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadReconstructionProject (params = {}) {
  return request({
    url: `${baseURL}/loadReconstructionProject`,
    params,
  })
}

/**
 * 上传某个企业的公司指标明细信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importCompanyIndicatorDetails (data) {
  return request({
    url: `${baseURL}/importCompanyIndicatorDetails`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的公司产品信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importCompanyProduct (data) {
  return request({
    url: `${baseURL}/importCompanyProduct`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的能源消费结构信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importEnergyConsumptionStructure (data) {
  return request({
    url: `${baseURL}/importEnergyConsumptionStructure`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的能源消费结构附表
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importEnergyConsumptionStructureSchedule (data) {
  return request({
    url: `${baseURL}/importEnergyConsumptionStructureSchedule`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的主要耗能设备状况信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importEquipmentStatus (data) {
  return request({
    url: `${baseURL}/importEquipmentStatus`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的进度节能目标完成情况
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId?: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importGoalCompletionStatus (data) {
  return request({
    url: `${baseURL}/importGoalCompletionStatus`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的单位产品综合能耗信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importProductEnergyConsumption (data) {
  return request({
    url: `${baseURL}/importProductEnergyConsumption`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 上传某个企业的节能改造项目信息
 * @param data{{
 *   year: string;
 *   quarter: string;
 *   tenantId: string;
 *   file: binary
 * }}
 * @returns {*}
 */
export function importReconstructionProject (data) {
  return request({
    url: `${baseURL}/importReconstructionProject`,
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    method: 'post',
    data,
  })
}

//
/**
 * 查看某个企业的单位详情信息
 * @param params{{
 *   year?: string;
 *   quarter?: string;
 *   tenantId?: string;
 * }}
 * @returns {Promise<any>}
 */
export function loadUpdateUnitDetails (params = {}) {
  return request({
    url: `${baseURL}/loadUpdateUnitDetails`,
    params
  })
}

/**
 * 保存或更新单位详情信息
 * @param data{{
     id: 'string',
     ssdq: 'string',
     ssly: 'string',
     hy: 'string',
     dwlx: 'string',
     dwxxmc: 'string',
     frdwdm: 'string',
     dwzcrq: 'string',
     dwzczb: 'string',
     fddbrxm: 'string',
     lxdh: 'string',
     sfyq: 'string',
     ssyqjtmc: 'string',
     dwdz: 'string',
     yzbm: 'string',
     xzqhdm: 'string',
     dzyx: 'string',
     nygljgmc: 'string',
     cz: 'string',
     zgjnldxm: 'string',
     lxdh1: 'string',
     nyglfzrxm: 'string',
     sj: 'string',
     nyglszh: 'string',
     sftgnygltxrz: 'string',
     tgrq: 'string',
     rzjg: 'string',
     bqgyzcz: 'string',
     sngyzcz: 'string',
     tbgyzcz: 'string',
     bqjgzs: 'string',
     snjgzs: 'string',
     tbjgzs: 'string',
     bqgyzczkbj: 'string',
     sngyzczkbj: 'string',
     tbgyzczkbj: 'string',
     bqxssr: 'string',
     snxssr: 'string',
     tbxssr: 'string',
     bqsjls: 'string',
     snsjls: 'string',
     tbsjls: 'string',
     bqcyry: 'string',
     sncyry: 'string',
     tbcyry: 'string',
     bqnyglsrs: 'string',
     snnyglsrs: 'string',
     tbnyglsrs: 'string',
     bqsccb: 'string',
     snsccb: 'string',
     tbsccb: 'string',
     bqnyxfcb: 'string',
     snnyxfcb: 'string',
     tbnyxfcb: 'string',
     bqnyxfzsccbbl: 'string',
     snnyxfzsccbbl: 'string',
     tbnyxfzsccbbl: 'string',
     bqzhnyxfl: 'string',
     snzhnyxfl: 'string',
     tbzhnyxfl: 'string',
     bqdwzczzhnh: 'string',
     sndwzczzhnh: 'string',
     tbdwzczzhnh: 'string',
     bqzzjrl: 'string',
     snzzjrl: 'string',
     tbzzjrl: 'string',
     bz: 'string',
     year: 'string',
     quarter: 'string'
 * }}
 * @returns {Promise<any>}
 */
export function saveOrUpdateUnitDetails (data) {
  return request({
    url: `${baseURL}/saveOrUpdateUnitDetails`,
    method: 'post',
    data,
  })
}

//
/**
 * 企业年报一键导出
 * @param params{{
 *   year: string;
 *   quarter: string;
 * }}
 * @returns {*}
 */
export function submitAnnualReport (params) {
  return request({
    url: `${baseURL}/submitAnnualReport`,
    params,
  })
}

/**
 * 检验能源消费结构信息
 */
export function checkEnergyConsumptionStructure (data) {
  return request({
    url: `${baseURL}/checkEnergyConsumptionStructure`,
    method: 'post',
    data,
  })
}

/**
 * 审核能源消费结构附表
 * @param {{tenantId:string,tableId: string,reportStatus:number,year:string,quarter:string,content?: '',regionCode?:string,energyLevel?:string}} data
 * @returns
 */
export function statusEnergyConsumptionStructureSchedule (data) {
  return request({
    url: `${baseURL}/statusEnergyConsumptionStructureSchedule`,
    method: 'post',
    data,
  })
}

/**
 *
 * @param {{
 * tenantId: string | number
 * tableIdList: (string | number)[]
 * reportStatus: number | string
 * year: string | number
 * quarter: string | number
 * }} data
 * @returns
 */
export function statusEnergyConsumptionStructureSchedule2 (data) {
  return request({
    url: `${baseURL}/audit`,
    method: 'post',
    data,
  })
}

/**
 * 企业端一键上报
 * @param {{
 * year: string | number
 * quarter: string | number
 * tenantId: string | number
 * tableIdList: (string|number)[]
 * }} params
 * @returns
 */
export function quickReport (params) {
  return request({
    url: `${baseURL}/apply`,
    method: 'post',
    data: params
  })
}

/** 查询最近的填报人信息 */
export function loadLastReportUser (params) {
  return request({
    url: `${baseURL}/lastInformer`,
    params,
  })
}


/** 导出工业年能源消费结构表 表1-2 */
export function exportEnergyConsumptionStructure (data) {
  return request({
    url: `${baseURL}/exportEnergyConsumptionStructure`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 导出工业季能源消费结构附表 表1-2-1 */
export function exportEnergyConsumptionStructureSchedule (data) {
  return request({
    url: `${baseURL}/exportEnergyConsumptionStructureSchedule`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 导出进度节能目标完成情况表 表1-4 */
export function exportGoalCompletionStatus (data) {
  return request({
    url: `${baseURL}/exportGoalCompletionStatus`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 导出单位产品综合能耗情况表 表1-3 */
export function exportProductEnergyConsumption (data) {
  return request({
    url: `${baseURL}/exportProductEnergyConsumption`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 导出工业年节能改造项目情况表 表1-5 */
export function exportReconstructionProject (data) {
  return request({
    url: `${baseURL}/exportReconstructionProject`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 导出工业年企业基本情况表 表1-1 */
export function exportUnitDetails (data) {
  return request({
    url: `${baseURL}/exportUnitDetails`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}

/** 一键导出报表(多个报表对应多个sheet) */
export function exportReport (year, quarter, enterpriseId) {
  return request({
    url: quarter === 5
      ? `${baseURL}/export/year/${year}/${quarter}/${enterpriseId}`
      : `${baseURL}/export/quarter/${year}/${quarter}/${enterpriseId}`,
    method: 'post',
    responseType: 'blob'
  })
}

/**
 * 获取表1-4的“五年计划”
 * @param {number} year year > 2001 && year < 2450
 * @return {Promise<{planNum: number, smallNumeralName: string, yearList: number[]}>} response
 */
export function getFiveYearPlanInfo (year) {
  return request({
    url: `${baseURL}/getFiveYearPlanInfo?year=${year}`
  })
}
